﻿using DLV.Utilities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DLV.Utilities;
using DLV.Library.Utilities;
using System.Globalization;

namespace DLV.Data.Entities
{
    public class PriceController
    {

        public int InsertPrice(PriceInfo info)
        {
            return SQL.InsertPrice(info.ItemId, info.ItemType, info.Time, info.SalePrice, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status,info.Season, info.BeginDate, info.EndDate,info.TicketType, info.Rated,info.FlightArrivals,info.SalePriceChild, info.PriceBaby);
        }
        public void UpdatePrice(PriceInfo info)
        {
            SQL.UpdatePrice(info.PriceId, info.ItemId, info.ItemType, info.Time, info.SalePrice, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status, info.Season, info.BeginDate, info.EndDate,info.TicketType, info.Rated, info.FlightArrivals, info.SalePriceChild, info.PriceBaby);
        }
        public void DeletePrice(PriceInfo info)
        {
            DeletePrice(info.PriceId);
        }
        public void DeletePrice(int priceId)
        {
            SQL.DeletePrice(priceId);
        }
        public PriceInfo GetPrice(int priceId)
        {
            return CBO.FillObject<PriceInfo>(SQL.GetPrice(priceId));
        }
        public List<PriceInfo> ListPrice()
        {
            return CBO.FillCollection<PriceInfo>(SQL.ListPrice());
        }
        public DataTable SelectPrice()
        {
            return CBO.ConvertToDataTable(ListPrice(), typeof(PriceInfo));
        }
        
        public List<PriceInfo> ListPriceByType(int type)
        {
            return CBO.FillCollection<PriceInfo>(SQL.ListPriceByType(type));         
        }

        public List<PriceInfo> ListPriceBySchedule(int type,int scheduleId)
        {
            return CBO.FillCollection<PriceInfo>(SQL.ListPriceBySchedule(type,scheduleId));
        }
        public List<PriceInfo> ListPriceBy(int type, int scheduleId, DateTime date, string flightArrival, int concernId,string season)
        {
            return CBO.FillCollection<PriceInfo>(SQL.ListPriceBy( type, scheduleId,  date,  flightArrival,  concernId,season));
        }
        public List<PriceInfo> ListPriceByCar(int type, int scheduleId, DateTime date, string soCho, int concernId, int yearCar, string season)
        {
            return CBO.FillCollection<PriceInfo>(SQL.ListPriceByCar(type, scheduleId, date, soCho, concernId, yearCar, season));
        }
        public List<PriceInfo> ListPriceByMenu(int type, int restaurantId, int menuTypeId, string seasonTour, DateTime date)
        {
            return CBO.FillCollection<PriceInfo>(SQL.ListPriceByMenu(type, restaurantId, menuTypeId, seasonTour, date));
        }
        public List<PriceInfo> ListPriceByDvk(int type, int partnerId, int locationId, string seasonTour)
        {
            return CBO.FillCollection<PriceInfo>(SQL.ListPriceByDvk(type, partnerId, locationId, seasonTour));
        }
        public DataTable SelectPriceByType(int itemType)
        {
            return CBO.ConvertToDataTable(ListPriceByType(itemType), typeof(PriceInfo));
        }

        public List<PriceInfo> ListPriceByHotelAndType(int hotelId)
        {
            return CBO.FillCollection<PriceInfo>(SQL.ListPriceByHotelAndType(hotelId));         
        }

        public PriceInfo GetPriceByRoom(int roomId, DateTime dateBegin)
        {
            return CBO.FillObject<PriceInfo>(SQL.GetPriceByRoom(roomId,dateBegin));
        }
        public PriceInfo GetPriceByInsurance(int insuranceId, DateTime dateBegin)
        {
            return CBO.FillObject<PriceInfo>(SQL.GetPriceByInsurance(insuranceId, dateBegin));
        }
        public Dictionary<object, object> ListPriceLookup()
        {
            var users = ListPrice().Where(p=>p.Status==(int)Globals.DocumentStatus.Use).OrderBy(p=>p.SalePrice);
            var dicusers = new Dictionary<object, object>();
            foreach (PriceInfo info in users)
                dicusers.Add(info.PriceId, info.SalePrice.ToString("#,###", new CultureInfo("vi-VN")) + " VND");

            return dicusers;
        }
    }
}
